import hUpload from './hUpload.vue'

export const upload = (mode: boolean = false) => {
    return new Promise((resolve) => {
        const uploadInstance: any = createApp(hUpload, {
            mode
        })
        const mountNode = document.createElement('div')
        document.getElementById('app').append(mountNode)
        uploadInstance.mount(mountNode)
        if (uploadInstance) {
            uploadInstance._instance?.proxy?.upload()
            // vue3的$on方法已移除
            uploadInstance._instance?.proxy?.Mit.on('uploadSuccess', (url) => {
                console.log(url);
                resolve(url)
                uploadInstance.unmount(mountNode)
                document.getElementById('app').removeChild(mountNode)
            })
        }
    })
}
